package io.test;

import java.io.*;
import java.util.Scanner;

public class CreateUser {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Scanner scan = new Scanner(System.in);
        System.out.print("请输入用户名:");
        String name = scan.nextLine();
        FileOutputStream fos = new FileOutputStream("src/io/test/"+name+".obj");
        ObjectOutputStream bos = new ObjectOutputStream(fos);//对象输出流接收对象
        System.out.print("请输入用户密码:");
        String pwd = scan.nextLine();
        System.out.print("请输入用户昵称:");
        String nick = scan.nextLine();
        System.out.print("请输入用户年龄:");
        int age = scan.nextInt();
        User user = new User(name,pwd,nick,age);
        bos.writeObject(user);
        System.out.println("写入完毕!");
        bos.close();
        /*test*/
        System.out.println("====");
        FileInputStream fis = new FileInputStream("src/io/test/"+name+".obj");
        ObjectInputStream bis = new ObjectInputStream(fis);
        User user1 = (User) bis.readObject();
        System.out.println(user1);
        bis.close();
    }
}
